Hide command prompt in Selenium ChromeDriver 您所在的位置:网站首页 selenium prompt Hide command prompt in Selenium ChromeDriver

Hide command prompt in Selenium ChromeDriver

2023-04-04 11:44| 来源: 网络整理| 查看: 265

I found the way to replicate the above code in python (more or less) Used this fix as base to my inspiration.

After hours of struggling (and also really bad words), I've made this commit on github bywhich console prompt behaviour is now easily changable via code. I will try to make it available in the official sources. Hope it will make you save time and patience.

STEP 1

Locate service.py, generally in "X:\YourPythonFold\Lib\site-packages\selenium\webdriver\common\service.py"

STEP 2

Replace these lines (n掳 72-76 approximately, below start method def):

self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)

with

if any("hide_console" in arg for arg in self.command_line_args()): self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, creationflags=0x08000000) else: self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)

Finally in your code, when you setup your driver (I chose Chrome as example):

args = ["hide_console", ] driver = webdriver.Chrome("your-path-to-chromedriver.exe", service_args=args, ...)

When edit the source code, be careful to PEP! Do not use tabs, just spaces!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有